<?php
class CdeUsersAnswer extends AppModel {

	var $name = 'CdeUsersAnswer';
	var $primaryKey = 'uid,cde_answer_id';
	function getUserAnswer($unitid=null,$moduleid=null,$userid=null) {
		$tempt=$this->query('SELECT cde_answer_id FROM cde_users_answers where uid= '.$userid.' and cde_answer_id in (select id FROM cde_answers where cde_module_id='.$moduleid .')');
		return $tempt;
	}
	function deleteOldAnswer($moduleid=null,$userid=null) {
		$this->query('delete FROM cde_users_answers where uid= '.$userid.' and cde_answer_id in (select id FROM cde_answers where cde_module_id='.$moduleid .')');
	}
	function addNewAnswer($answerid=null,$userid=null) {
		$sql='insert into cde_users_answers values('.$userid.','.$answerid.')';
		$this->query($sql);
	}
	function delete($unitid=null,$userid=null) {
		$sql='delete from cde_users_answers where uid='.$userid.' and cde_answer_id in
		(select id from cde_answers where cde_module_id in
		(select id from cde_modules where cde_unit_id='.$unitid.'))';
		$this->query($sql);
	}
}
?>